//
//  MainViewController.swift
//  LCYWeiBo
//
//  Created by 李长友 on 16/8/30.
//  Copyright © 2016年 app. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    /// 发布按钮
    private lazy var composeButton = UIButton(imageName: "tabbar_compose_icon_add", backgroundImageName: "tabbar_compose_button")
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        addChildViewController(HomeViewController(), title: "首页", image: "tabbar_home")
        addChildViewController(MessageViewController(), title: "消息", image: "tabbar_message_center")
        addChildViewController(UIViewController())
        addChildViewController(DiscoverViewController(), title: "发现", image: "tabbar_discover")
        addChildViewController(ProfileViewController(), title: "我", image: "tabbar_profile")

        setupComposeButton()
    }
    
    func addChildViewController(childController: UIViewController, title: String, image: String) {

        childController.title = title
        childController.tabBarItem.image = UIImage(named: image)
        childController.tabBarItem.selectedImage = UIImage(named: image + "_highlighted")
        let childNavigationController = UINavigationController(rootViewController: childController)
        addChildViewController(childNavigationController)
        childController.tabBarItem.enabled = true
    }
    
    override func addChildViewController(childController: UIViewController) {
        super.addChildViewController(childController)
        
        childController.tabBarItem.enabled = false
    }
}

// MARK: - 设置UI
extension MainViewController {
    
    private func setupComposeButton() {
        
        composeButton.center = CGPointMake(tabBar.center.x, tabBar.bounds.size.height * 0.5)
        composeButton.addTarget(self, action: #selector(MainViewController.composeButtonClick), forControlEvents: .TouchUpInside)
        tabBar.addSubview(composeButton)
    }
}

// MARK: - 按钮点击事件
extension MainViewController {
    
    @objc private func composeButtonClick() {

    }
}

//extension MainViewController: UITabBarControllerDelegate {
//    override func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
//        
//    }
//    
//    func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) {
//        
//    }
//}